﻿/// <reference path="central.core.js" />
/// <reference path="knockout.mapping-latest.debug.js" />
/// <reference path="knockout-2.1.0.js" />

(function (cental, ko) {
    "use strict";

    //central.utils.mappings = {
    //    queryParamsMapping: {
    //        "Filters":
    //    }
    //};

    ///////////////////////////////////////////////////////////////
    //  контрол QueryBuilder в системе Central
    //  автор:          Central
    //  зависит от:     central.js
    ///////////////////////////////////////////////////////////////

    central.controls.QueryBuilder = function (controller, action, queryParams) {
        var self = this,
            controller = controller,
            action = action,
            queryParamsInternal = ko.observable(
            {
                "EntityName": ko.observable(),
                "Filters": ko.observable({
                    "LogicalOperator": ko.observable(),
                    "FilterParams": ko.observableArray([]),
                    "JsonFilterManagers": ko.observable({
                        "LogicalOperator": ko.observable(),
                        "FilterParams": ko.observableArray([]),
                        "JsonFilterManagers": ko.observable()
                    })
                }),
                "Sorters": ko.observable({
                    "SortParams": ko.observableArray([])
                }),
                "Groups": ko.observable({
                    "GroupParams": ko.observableArray([]),
                    "FieldNameForCount": ko.observable()
                })
            });

        ko.mapping.fromJS(queryParams, {} /*central.utils.mappings.queryParamsMapping*/, queryParamsInternal)

        queryParamsInternal.deleteFilter = function () {
            alert("хуй");
        };

        return {
            controller: controller,
            action: action,
            queryParams: queryParamsInternal
        }
    }
})(central, ko);